<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Feedback_model extends MY_Model
{

	public function feedbackList($data = array()){
        $where = " ";
        if(!empty($data['starttime'])){
            $where .= " AND addtime >= {$data['starttime']}";
        }
        if(!empty($data['endtime'])){
            $data['endtime'] = $data['endtime']+3600*24;
            $where .= " AND addtime <= {$data['endtime']}";
        }
        if(!empty($data['content'])){
            $where .= " AND content like '%{$data['content']}%'";
        }
        if(!empty($data['contact'])){
            $where .= " AND username like '%{$data['contact']}%' or feedbackperson like '%{$data['contact']}%'";
        }
        if(($data['status'] === "0" || $data['status'] == 1 || $data['status'] == 2 || $data['status'] == 3 || $data['status'] == -1)){
            $where .= " AND status={$data['status']}";
        }

         $sql  = "SELECT * FROM yy_feedback WHERE isDel <> 1 {$where} ORDER BY addtime desc";
        $query = $this->db->query($sql);
        return $query->result_array();
    }


    public function get_feedbact_cnt($data = array()){
        $where = " ";
        if(!empty($data['starttime'])){
            $where .= " AND addtime >= {$data['starttime']}";
        }
        if(!empty($data['endtime'])){
            $data['endtime'] = $data['endtime']+3600*24;
            $where .= " AND addtime <= {$data['endtime']}";
        }
        if(!empty($data['content'])){
            $where .= " AND content like '%{$data['content']}%'";
        }
        if(!empty($data['contact'])){
            $where .= " AND username like '%{$data['contact']}%' or feedbackperson like '%{$data['contact']}%'";
        }
        if(($data['status'] === "0" || $data['status'] == 1 || $data['status'] == 2 || $data['status'] == 3 || $data['status'] == -1)){
            $where .= " AND status={$data['status']}";
        }

         $sql  = "SELECT * FROM yy_feedback WHERE isDel <> 1 {$where}";
        $query = $this->db->query($sql);
        return $query->num_rows();
    }


    //编辑状态
    public function edit_status($id,$status){
        $this->db->where("id",$id);
        $data = array(
            'status'=>$status
        );
        $res = $this->db->update("yy_feedback",$data);
        return $res;
    }

    public function delFeedback($id){
        $this->db->where("id",$id);
        $data = array(
            'isDel'=>1
        );
        $res = $this->db->update("yy_feedback",$data);
        return $res;
    }

}


